Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
Difference between import a module with and without ".js" in es6 module

I'm recently learning chrome extension development, and find out that: When I use

import { foo } from "./index"

in background.js, I will get an error: An unknown error occurred when fetching the script., while using

import { foo } from "./index.js"

Everything just works properly. Could someone please tell me the difference between these two ways?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

ES6 needs you to reference a file for it to fetch.

Extension-less or a directory to use index from are supported by external loaders such as webpack, with correct configurations.

With these, if you import without extension, it will look for an index.js inside your import path as if it were a folder.

Or If you have a folder foo, and inside it a file index.js, you can import ./foo without the extension and it will import the index file.

Directly in ES6 as far as I'm aware (e.g. for Chrome browser direct interpretation without some loader), I believe a full file path is necessary for local imports, so you should include the .js extension when you want to import a specific file.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!